<template>
  <el-row type="flex" justify="space-between" style="width: 100%">
    <el-col>
      <span>{{ node.name }}</span>
    </el-col>
    <el-col :span="8">
      <span class="names">{{ node.manager }}</span>
      <el-dropdown @command="handleCommand">
        <span class="el-dropdown-link">
          下拉菜单<i class="el-icon-arrow-down el-icon--right" />
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="add"> 添加子部门 </el-dropdown-item>
          <el-dropdown-item v-if="boo" command="edit">
            编辑部门
          </el-dropdown-item>
          <el-dropdown-item v-if="boo" command="del">删除部门</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </el-col>
  </el-row>
</template>

<script>
export default {
  name: 'TreeNode',
  props: {
    node: {
      type: Object,
      required: true
    },
    boo: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    handleCommand(type) {
      if (type === 'add') {
        this.$emit('addDept', this.node)
      } else if (type === 'edit') {
        this.$emit('editDept', this.node)
      } else {
        this.$emit('delDept', this.node)
      }
    }
  }
}
</script>

<style scoped lang="scss">
.names {
  margin-right: 10px;
}
</style>
